import requests


def get_xb(query_str, useragent):
    params = {
        'query': query_str,
        'user-agent': useragent
    }
    try:
        resp = requests.get('http://localhost:3000/x-bogus/', params=params)
        xbogus = resp.json()['X-Bogus']
    except:
        import execjs
        with open('js/webmssdk.es5.min.js', encoding='utf-8') as fp:
            js = fp.read()
        xbogus = execjs.compile(js).call('get_xb', query_str, useragent)
    return xbogus

if __name__ == '__main__':
    xbogus = get_xb('', '')
    print(xbogus)